﻿using System;
using System.IO;
using System.Text;

namespace DatesAndStrings
{
    class Program
    {
         

        static void Main(string[] args)
        {

            DateTime dt = DateTime.Now;
            Console.WriteLine(dt.ToString());
            
            var a=  dt.ToFileTime().ToString(); 
            var b=  dt.ToFileTimeUtc().ToString(); 
            var c=dt.ToLocalTime().ToString(); 
            var e=  dt.ToLongDateString().ToString();
            var f = dt.ToLongTimeString().ToString();
            var g = dt.ToOADate().ToString();
            var h = dt.ToShortDateString().ToString();
            var d = dt.ToShortTimeString().ToString();
            var j = dt.ToUniversalTime().ToString();
            var k = dt.Year.ToString();
            var l = dt.Date.ToString();
            var m = dt.DayOfWeek.ToString();
            var n = dt.DayOfYear.ToString();
            var o = dt.Hour.ToString();
            var p = dt.Millisecond.ToString();
            var q = dt.Minute.ToString();
            var r = dt.Month.ToString();
            var s = dt.Second.ToString();
            var t = dt.Ticks.ToString();
            var u = dt.TimeOfDay.ToString();
            var v = dt.ToString();
            var w = dt.AddYears(1).ToString();
            var x = dt.AddDays(1.1).ToString();
            var y = dt.AddHours(1.1).ToString();
            var z = dt.AddMilliseconds(1.1).ToString();
            var aa = dt.AddMonths(1).ToString();
            var bb= dt.AddSeconds(1.1).ToString();
            var cc= dt.AddMinutes(1.1).ToString();
            var dd= dt.AddTicks(1000).ToString();
            var ee= dt.CompareTo(dt).ToString();
            var ff= dt.AddDays(3.0).ToString();
            var gg= dt.Equals("2005-11-6 16:11:04").ToString();
            var hh= dt.Equals(dt).ToString();
            var ii= dt.GetHashCode().ToString();
            var jj= dt.GetType().ToString();
            var kk= dt.GetTypeCode().ToString();

            var ll = dt.GetDateTimeFormats('s')[0].ToString();
            var mm = dt.GetDateTimeFormats('t')[0].ToString();
            var nn = dt.GetDateTimeFormats('y')[0].ToString();
            var oo = dt.GetDateTimeFormats('D')[0].ToString();
            var pp = dt.GetDateTimeFormats('D')[1].ToString();
            var qq = dt.GetDateTimeFormats('D')[2].ToString();
            var rr = dt.GetDateTimeFormats('D')[3].ToString();
            var ss = dt.GetDateTimeFormats('M')[0].ToString();
            var tt = dt.GetDateTimeFormats('f')[0].ToString();
            var uu = dt.GetDateTimeFormats('g')[0].ToString();
            var vv = dt.GetDateTimeFormats('r')[0].ToString();
            var ww = string.Format("{0:d}", dt);
            var xx = string.Format("{0:D}", dt);
            var yy = string.Format("{0:f}", dt);
            var zz = string.Format("{0:F}", dt);
            var aaa = string.Format("{0:g}", dt);
            var bbb = string.Format("{0:G}", dt);
            var ccc = string.Format("{0:M}", dt);
            var ddd = string.Format("{0:R}", dt);
            var eee = string.Format("{0:s}", dt);
            var fff = string.Format("{0:t}", dt);
            var ggg = string.Format("{0:T}", dt);
            var hhh = string.Format("{0:u}", dt);
            var iii = string.Format("{0:U}", dt);
            var jjj = string.Format("{0:Y}", dt);
            var kkk = string.Format("{0}", dt);
            var lll = string.Format("{0:yyyyMMddHHmmssffff}", dt);
            Console.WriteLine(a);
            Console.WriteLine(b);
            Console.WriteLine(c);
            Console.WriteLine(e);
            Console.WriteLine(f);
            Console.WriteLine(g);
            Console.WriteLine(h);
            
            Console.WriteLine(j);
            Console.WriteLine(k);
            Console.WriteLine(l);
            Console.WriteLine(m);
            Console.WriteLine(n);
            Console.WriteLine(o);
            Console.WriteLine(p);
            Console.WriteLine(q);
            Console.WriteLine(r);
            Console.WriteLine(s);
            Console.WriteLine(t);
            Console.WriteLine(u);
            Console.WriteLine(v);
            Console.WriteLine(w);
            Console.WriteLine(x);
            Console.WriteLine(y);
            Console.WriteLine(z);
            Console.WriteLine(aa);
            Console.WriteLine(bb);
            Console.WriteLine(cc);
            Console.WriteLine(dd);
            Console.WriteLine(ee);
            Console.WriteLine(ff);
            Console.WriteLine(gg);
            Console.WriteLine(hh);
            Console.WriteLine(ii);
            Console.WriteLine(jj);
            Console.WriteLine(kk);
            Console.WriteLine(ww);
            Console.WriteLine(xx);
            Console.WriteLine(yy);
            Console.WriteLine(zz);
            Console.WriteLine(aaa);
            Console.WriteLine(bbb);
            Console.WriteLine(ccc);
            Console.WriteLine(ddd);

            Console.WriteLine(eee);
            Console.WriteLine(fff);




            //计算2个日期之间的天数差
            DateTime dt1 = Convert.ToDateTime("2007-8-1");
            DateTime dt2 = Convert.ToDateTime("2007-8-15");
            TimeSpan span = dt2.Subtract(dt1);
            int dayDiff = span.Days + 1;

          //  计算某年某月的天数
            
            int days = DateTime.DaysInMonth(2007, 8);
            days = 31;
           // 给日期增加一天、减少一天
            
            DateTime dt3 = DateTime.Now;
            dt.AddDays(1); //增加一天
            dt.AddDays(-1);//减少一天




            string mystring = "I like this food,are you?";
            char[] separators = { ' ', ',', '?', ':', '!' };
            int startpos = 0;
            int endpos = 0;
            do
            {
                endpos = mystring.IndexOfAny(separators, startpos);
                if (endpos == -1) endpos = mystring.Length;
                if (endpos != startpos)
                    Console.WriteLine(mystring.Substring(startpos, (endpos - startpos)));
                startpos = (endpos + 1);
            } while (startpos < mystring.Length);




            //点到字符串顺序
            string mystrings = "你们好";
            char[] mychars = mystrings.ToCharArray();
            Array.Reverse(mychars);
            Console.WriteLine(mystrings);
            Console.WriteLine(mychars);



            






            Console.WriteLine("请输入您电脑的IP地址：");
            string str = Console.ReadLine();
            string str1 = str.Replace(".", "\t");
            Console.WriteLine("您的ip地址各部分分别为：" + "\n" + str1);
            Console.ReadKey();





            Console.WriteLine("请输入一个URL域名：");
            string strr = Console.ReadLine();
            int index = strr.LastIndexOf('.');
            string str2 = strr.Substring(index);
            Console.WriteLine("您输入的URL顶级域名是：" + str2);
            switch (str2)  
            { 
                                case ".com":
                      Console.WriteLine("这是一个商业网站");
                                     break;
                                case ".net":
                      Console.WriteLine("这是一个网络服务机构网站");
                                     break;
                                case ".org":
                      Console.WriteLine("这是一个非营利组织网站");
                                     break;
                                case ".gov":
                      Console.WriteLine("这是一个政府机构网站");
                                     break;
                                case ".edu":
                      Console.WriteLine("这是一个教育机构网站");
                                     break;
                                default:
                      Console.WriteLine("您的输入有误，请正确输入您的网址！");
                                     break;
                            }
                      Console.ReadKey();



            Console.WriteLine("请输入一串字符，并用空格分隔单词：");
            string str3 = Console.ReadLine();
            string[] array1 = str3.Split(' ');
            Console.WriteLine("分割后的字符串为：");
            foreach (var item in array1)
            {
            Console.WriteLine(item);
            }
            string str4 = str1.Replace(" ", "_");
            Console.WriteLine("链接后的字符串为：{0}", str4);





            Console.WriteLine("请输入一个字符串，各单词以空格分隔：");
            string str5 = Console.ReadLine();
            string[] array2 = str5.Split(' ');
            string temp = " ";
            foreach (var item in array2)
            {
            temp += item.Substring(0, 1).ToUpper() + item.Substring(1);
            }
            string result = temp.Substring(0, 1).ToLower() + temp.Substring(1);
            Console.WriteLine("按Camel规则转换后的名称是：{0}", result);






            Console.WriteLine("请输入您的邮箱：");
            string xiaoyou = Console.ReadLine();
            int index3 = xiaoyou.IndexOf("@");
            int index4 = xiaoyou.IndexOf(".");
            if (index3 < 0 || index4 < 0)
            {
            Console.WriteLine("邮箱必须包含@符号或 . 符号！");
            }
            string str6 = xiaoyou.Substring(0, xiaoyou.IndexOf("@"));
            string str7 = xiaoyou.Substring(xiaoyou.LastIndexOf(".") + 1);
            Console.WriteLine("邮箱{0}的用户名是{1}，域名是{2}", xiaoyou, str6, str7);
            Console.ReadKey();



            string number = "6,16,26,36,46,56,66";
            string[] stringArry = number.Split(',');


            string number1 = "1,2,3";
            number1 = number1.Substring(0, number1.Length - 1);
            Console.WriteLine(number1);


            RandomNumber randomNumber = new RandomNumber();
            Console.WriteLine(randomNumber.PrintRandomNumber());
        }
    }
}
